package com.example.ymm.modules1.service.impl.hl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.modules1.entity.hl.dkn.DknPlanItem;
import com.example.ymm.modules1.mapper.hl.DknPlanItemMapper;
import com.example.ymm.modules1.query.hl.DknPlanItemQueryCriteria;
import com.example.ymm.modules1.service.hl.DknPlanItemService;
import com.example.ymm.util.DateUtils;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
@DSTransactional
@Slf4j
@DS("slave2")
public class DknPlanItemServiceImpl extends BaseServiceImpl<DknPlanItemMapper, DknPlanItem> implements DknPlanItemService {

    @Override
    public List<DknPlanItem> queryAll(DknPlanItemQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DknPlanItem.class, criteria);
        predicate.orderByAsc("sort");
        List<DknPlanItem> result =baseMapper.selectList(predicate);
        return result;
    }

    @Override
    public List<DknPlanItem> getDateRangeItems(List<String> date_rang) {

        List<String> rangeDateCards = DateUtils.getRangeDateCards(date_rang.get(0), date_rang.get(1), 0);
        DknPlanItemQueryCriteria criteria = new DknPlanItemQueryCriteria();
        criteria.setDateIn(rangeDateCards);
        return baseMapper.getDateRangeItems(criteria);
    }
}
